﻿Imports System.Windows.Forms

Public Class frmTelefonesSuporte
    Private Const fVNC As String = "interfacenet.myvnc.com:55"
    Private Const fUsuarioFtp As String = "suporte"
    Private Const fSenhaFtp As String = "ftpsuporte"
    Private fArquivo

    Function SoNumeros(ByVal Keyascii As Short) As Short
        If InStr("1234567890", Chr(Keyascii)) = 0 Then
            SoNumeros = 0
        Else
            SoNumeros = Keyascii
        End If
        Select Case Keyascii
            Case 8
                SoNumeros = Keyascii
            Case 13
                SoNumeros = Keyascii
            Case 32
                SoNumeros = Keyascii
        End Select
    End Function
    Private Sub VNC()
        Try
            If txtCodigo.Text <> "" Then
                If Dir(Application.StartupPath & "\winvnc4.exe") = "" Then
                    If Dir("C:\PDV\VNC4\winvnc4.exe") <> "" Then
                        IO.File.Copy("C:\PDV\VNC4\winvnc4.exe", Application.StartupPath & "\winvnc4.exe")
                    ElseIf Dir(Mid(pDir, 1, 2) & "\PDV\VNC4\winvnc4.exe") <> "" Then
                        IO.File.Copy(Mid(pDir, 1, 2) & "PDV\VNC4\winvnc4.exe", Application.StartupPath & "\winvnc4.exe")
                    Else
                        Try
                            My.Computer.Network.DownloadFile("www.interfacenet.info/downloads/winvnc4.exe", pDir & "winvnc4.exe")
                        Catch ex As Exception
                            MsgBox("O VNC não foi encontrado no seu computador.' " & Application.StartupPath & "\winvnc4.exe'", vbExclamation, pMsgEmpresa)
                            Exit Sub
                        End Try
                    End If
                End If
                If Not existeProcessoAbertoLocal("winvnc4") Then
                    Shell(Chr(34) & Application.StartupPath & "\winvnc4.exe" & Chr(34) & " " & "-noconsole", AppWinStyle.Hide)
                End If
                Shell(Chr(34) & Application.StartupPath & "\winvnc4.exe" & Chr(34) & " " & "-connect " & fVNC & Int(txtCodigo.Text), AppWinStyle.Hide)
            Else
                MsgBox("Informe o código do atendente!", vbInformation, pMsgEmpresa)
                txtCodigo.Focus()
            End If
            Exit Sub
        Catch ex As Exception
            MsgBox("Ocorreu um erro ao conectar: " & ex.Message)
        End Try
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCodigo.KeyPress
        Dim KeyAscii As Short = CShort(Asc(e.KeyChar))
        KeyAscii = CShort(SoNumeros(KeyAscii))
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub btConectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btConectar.Click
        VNC()
        txtCodigo.Text = ""
    End Sub

    Private Sub frmTelefonesSuporte_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        ' Dim sLeitor As New IO.StreamReader("C:\pdv\suporte.html", System.Text.Encoding.Default)
        'Dim sPagina = sLeitor.ReadToEnd()
        Dim sDivChat = ""

        Try
            My.Computer.Network.Ping("www.google.com.br", 500)
            sDivChat = "<div align='center'>" & _
"<a href='http://www.interfacenet.info/livezila/chat.php' target='_self'>" & _
"<img src='http://www.interfacenet.info/livezila/image.php?id=01&amp;type=inlay' width='120' height='30' border='0' alt='Clique aqui para acessar o suporte online.'></a>" & _
"</div>"
        Catch ex As Exception
            sDivChat = "<div align= 'center'>" & _
                        "Você não está conectado à internet! Conexão necessária para acessar o chat</div>"
        End Try

        Dim sPaginaPadrao As String =
        "<html>" & _
        "<body topmargin='0' leftmargin='0'>" & _
        "<table border='0' cellpadding='0'>" & _
        "<tr><tr>" & _
"<td style='font-family:verdana'>" & _
"<div align='center' style='text-align:left;font-family:verdana;width:100%;background-color:silver'>" & _
"Nosso atendimento funciona de 2ª a 6ª, de 09:00 ás 18:00, pelo telefone:" & _
"</div>" & _
"<ul>" & _
"<li style='text-align:left;color:red'>(21) 3550-3500</li>" & _
"</ul>" & _
"</td>" & _
"</tr>" & _
"<tr><td>" & _
"<div align='center' style='text-align:left;font-family:verdana;width:100%;background-color:silver'>" & _
"Plantão exclusivo para<b><span> LOJAS </span></b>." & _
"<br>Sábados: De 09:00 às 22:00." & _
"<br>Domingos e Feriados: De 15:00 às 21:00." & _
"</div>" & _
"<ul>" & _
"<li style='text-align:left;color:red;font-family:verdana'>(21) 7843-7490</li>" & _
"<li style='text-align:left;color:red;font-family:verdana'>(21) 7842-0260</li>" & _
"</ul></td></tr>" & _
"<tr><td>" & _
"<div align='center' style='text-align:left;font-family:verdana;width:100%;background-color:silver'>Chat exclusivo para clientes <b><span> Fora </span></b> do estado do Rio de Janeiro.</div>" & _
"<br>" & _
sDivChat & _
"</td></tr>" & _
"</table>" & _
"</body> " & _
"</html>"

        browser.DocumentText = sPaginaPadrao
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            '  My.Computer.Network.UploadFile("C:\pdv\contatos.html", "ftp://interfacenet.myvnc.com/UPLOAD_NETBACKUP/contato.html", "suporte", "ftpsuporte", True, 100)
            Shell("%SystemRoot%\explorer.exe /n, /e, /select, C:\PDV", AppWinStyle.Hide)

        Catch ex As Exception
            MsgBox("Erro!" & ex.Message)
        End Try
    End Sub

    'Private Sub InitializeComponent()
    '    Me.SuspendLayout()
    '    '
    '    'frmTelefonesSuporte
    '    '
    '    Me.ClientSize = New System.Drawing.Size(549, 355)
    '    Me.Name = "frmTelefonesSuporte"
    '    Me.ResumeLayout(False)

    'End Sub

    Private Sub frmTelefonesSuporte_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Function txtCodigo() As Object
        Throw New NotImplementedException
    End Function

End Class